EAPI=8

inherit rust cargo

DESCRIPTION="Rust-based flamegraph generator"
HOMEPAGE="https://github.com/jonhoo/inferno"
SRC_URI="https://github.com/jonhoo/inferno/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="MIT Apache-2.0"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

RDEPEND=""
DEPEND=""

pkg_pretend() {
    if [[ "${FEATURES}" == *network-sandbox* ]]; then
        ewarn
        ewarn ">>> This package needs network access to fetch Rust crates."
        ewarn ">>> If you encounter build failures, try:"
        ewarn ">>>   FEATURES=\"-network-sandbox\" emerge -avt inferno"
        ewarn
    fi
}

src_unpack() {
	default
}

src_prepare() {
	default
}

src_compile() {
	export CARGO_PROFILE_RELEASE_STRIP=false
	# 不要使用 cargo_src_compile，会自动使用 cargo_env（依赖 cargo_gen_config）
	cargo build --release --all-targets || die "cargo build failed"
}

src_install() {
    local bins=(
        inferno-flamegraph
        inferno-diff-folded
        inferno-collapse-dtrace
        inferno-collapse-ghcprof
        inferno-collapse-guess
        inferno-collapse-perf
        inferno-collapse-recursive
        inferno-collapse-sample
        inferno-collapse-vsprof
        inferno-collapse-vtune
        inferno-collapse-xctrace
    )

    for bin in "${bins[@]}"; do
        dobin "target/release/${bin}" || die "dobin failed: ${bin}"
    done
}

